<template>
    <div>
        <x-header :left-options="{showBack: true}">相关活动</x-header>
        <img slot="header" src="../assets/relatedAct.jpg" style="width:100%;display:block;height: 150px">
        <group :title="(sponsor)" class="boxtwo">
            <div v-for="act in activity">
                <cell :title="(act.name)"
                      :link="{path:'/activitydetail',query:{actId:act.id,sponsorId:this.sponsorId}}"
                      :inline-desc='act.personNum'></cell>
            </div>
        </group>
    </div>
</template>


<script>
    import {Group, XHeader, Divider, Cell, Box, XImg} from 'vux'
    import request from 'superagent'

    export default {
        components: {
            Group,
            XHeader,
            Divider,
            Cell,
            Box,
            XImg
        },
        data () {
            return {
                activity: [],
                sponsor: ''
            }
        },
        created: function () {
            this.actId = this.$route.query.actId;
            this.sponsorId = this.$route.query.sponsorId;
            this.getData();
        },
        methods: {
            getData() {
                request.get('/wx/activity/relatedActivity')
                    .query({actId: this.actId, sponsorId: this.sponsorId})
                    .end((err, res) => {
                        console.log(res);
                        if (res.ok) {
                            this.activity = JSON.parse(res.text).data;
                            this.sponsor = this.activity[0].sponsorName + '发起的其他活动';
                        } else {
                            console.log('请求数据失败');
                        }
                    });
            },
        }
    }
</script>
<style scoped>
    .boxtwo {
        height: 450px;
        overflow-y: auto;
    }
</style>